<template>
    <div>
        <mian-layout @refresh="resetForm('search_data')">
            <template v-slot:conTop>
                <el-form size="mini" :inline="true" :model='search' ref="search_data" class="demo-form-inline search-form">
                    <el-form-item label="会员手机号码" prop="phone">
                        <el-input v-model="search.phone" placeholder="会员手机号码"></el-input>
                    </el-form-item>
                    <el-form-item label="创建时间" prop="dataTime">
                        <el-date-picker v-model="dataTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm" />
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" plain  icon="el-icon-search" @click="doSearch">搜索</el-button>
                        <el-button icon="el-icon-refresh-right" @click="resetForm('search_data')">重置</el-button>
                    </el-form-item>
                </el-form>   
            </template>
            <!-- <div class="btnBox" style="padding-bottom:10px">
                <el-button type="success" icon="el-icon-plus" size="mini" @click="$router.push('/artist/add')">新增艺术家</el-button>
            </div> -->
            <my-table :loading="loading" :lists="tableData" @selectionChange="tableSelect" @pageChange="handleChange" :sequence="true" :page='page'>
                
                <el-table-column property="userId" label="用户ID" align='center'></el-table-column>
                <el-table-column property="nick" label="昵称" align='center'></el-table-column>
                <el-table-column property="phone" label="会员手机号码" align='center'></el-table-column>
                <el-table-column property="recommendPhone" label="推荐人手机号码" align='center'>
                    <template slot-scope="scope">
                        <span>{{scope.row.recommendPhone || '--'}}</span>
                    </template>
                </el-table-column>
                <el-table-column property="points" label="积分" align='center'></el-table-column>
                <el-table-column property="createTime" label="注册时间" align='center'>
                    <template slot-scope="scope">
                        <span>{{scope.row.createTime}}</span>
                    </template>
                </el-table-column>
                
                
                <el-table-column prop="operation" align='center' label="操作" width="120">
                    <template slot-scope='scope'>
                        <el-button size="mini" icon="el-icon-search" @click="goDetail(scope.row,1)">查看</el-button>
                        <!-- <el-button size="mini" type="success" plain icon="el-icon-edit" @click="goDetail(scope.row,2)">修改</el-button>
                         <el-button size="mini" type="danger" icon="el-icon-delete" @click="del(scope.row)">删除</el-button>  -->
                    </template>
                </el-table-column>

            </my-table>
        </mian-layout>

    </div>
</template>
<script>
import {mapGetters} from "vuex"
import myTable from '@/components/public/myTable';
import {
  get_user_list,
} from '@/api/arApi'
export default {
    components:{
      myTable
    },
    data(){
        return{
            search:{
                phone:'',
                createTimeEnd: "",
                createTimeStart: ""
            },
            page:{
                pageSize:10,
                pageIndex:1,
			    total:0,
            },
            loading:true,
            tableData:[],
            multipleSelectionIds:[],
            dataTime:''
        }
    },
    computed:{
        ...mapGetters({
            'userInfo':'user/userInfo'
        })
    },
    created(){
        this.getList()
    },
    methods:{
        doSearch(){
            this.pageIndex = 1
            this.getList()
        },
        getList(){ 
            this.loading = true
            if(this.dataTime){
                this.search.createTimeStart = this.dataTime[0]
                this.search.createTimeEnd = this.dataTime[1]
            }
            get_user_list({
                limit: this.page.pageSize,
                page: this.page.pageIndex,
                ...this.search
            }).then(res=>{
                this.loading = false
                this.tableData = res.data
                this.page.total = res.total
            })
        },
        
        tableSelect(item){
            this.multipleSelectionIds = []
            for(let i=0;i<item.length;i++){
                this.multipleSelectionIds.push(item[i]._id)
            }
        },
        handleChange(index) {
            this.page.pageIndex = index;
            this.getList();
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dataTime = []
            for (const key in this.search) {
               this.search[key] = '' 
            }
            this.page.pageIndex = 1
            this.getList()
        },
        goDetail(item,onlyLook){
            //sessionStorage.setItem('details',JSON.stringify(item))
            this.$router.push(`/member/detail?id=${item.userId}&onlyLook=${onlyLook}`)
        }
    }
}
</script>